class MyPageHeader extends BaseEditMaster {
    constructor(dataId, currentTaskPrivileges, nextTaskPrivileges, pageStatus, pageListData,
            returnUrl, fetchDataUrl, saveUrl, exportUrl, printUrl) {
        super(dataId, currentTaskPrivileges, nextTaskPrivileges, pageStatus, pageListData,
                returnUrl, fetchDataUrl, saveUrl, exportUrl, printUrl);
    }
    // 得到加工合同数据
    GetEntityData() {
        let item = {};
        item['headerId'] = $("#HeaderId").val();
        item['contractNo'] = $.trim($("#ContractNo").val());
        item['dateOfSigned'] = $.trim($("#DateOfSigned").val());
        item['secondPartyId'] = $.trim($("#SecondPartyId").val());
        item['signedBy'] = $.trim($("#SignedBy").val());
        item['currencyId'] = $.trim($("#CurrencyId").val());
        item['taxRate'] = $.trim($("#TaxRate").val());
        item['invoiceTitle'] = $.trim($("#InvoiceTitle").val());
        item['advancePaymentFlag'] = $("#AdvancePaymentFlag").is(":checked") ? "1" : "0";   // 是否已经预付款
        item['description'] = $.trim($("#Description").val());
        item['createdBy'] = $.trim($("#UserId").val());
        item['updatedBy'] = $.trim($("#UserId").val());

        return JSON.stringify(item);
    }
    FillData(data) {
        let item = data.HeaderEntity;
        $("#HeaderId").val(item.headerId);
        $("#ContractNo").val(item.contractNo);
        $("#DateOfSigned").val(item.dateOfSigned);
        $("#SecondPartyId").val(item.secondPartyId);
        $("#SecondPartyName").val(item.secondPartyName);
        $("#SignedBy").val(item.signedBy);
        $("#SignedByName").val(item.signedByName);
        $("#CurrencyId").val(item.currencyId);
        $("#CurrencyName").val(item.currencyName);
        $("#Amount").val(item.amount);          // 总金额
        $("#TaxRate").val(item.taxRate);
        $("#InvoiceTitle").val(item.invoiceTitle);
        $("#Description").val(item.description);
        $("#UpdatedByName").val(item.updatedByName);
        $("#UpdatedDate").val(item.updatedDate);
        // 是否有预付款
        if (parseInt(item.advancePaymentFlag) === 1) {
            $("#AdvancePaymentFlag").prop("checked", true);
        } else {
            $("#AdvancePaymentFlag").prop("checked", false);
        }
        // 最后的审核人、审核日期
        $("#CheckedBy").val(item.checkedBy);
        $("#CheckedByName").val(item.checkedByName);
        $("#CheckedDate").val(item.checkedDate === null ? '' : item.checkedDate);
        $("#CheckedStatus").val(item.checkedStatus);
        $('#FlowOrderNo').val(item.flowOrderNo);

        // 显示明细数据
        _InstancePageLines.BuildDataTable(data.LinesList);
        _InstancePageLinesMo.BuildDataTable(data.LinesMoList);

        this.currentTaskPrivileges = item.currentTaskPrivileges;
        this.nextTaskPrivileges = item.nextTaskPrivileges;
        this.unCheckFlag = item.unCheckFlag;
        this.SetPageElementStatus(this.HidePageElement, this.ShowPageElement, function () {
            _InstancePageLines.AutoAdjustTableHeightForLines();
            _InstancePageLinesMo.AutoAdjustTableHeightForLines();
        });

        $("#ContractNo").focus();
    }
    Save() {
        super.Save(function (data, _this) {
            if (data > 0) {
                if (parseInt(_this.pageStatus) === 1) {
                    $("#HeaderId").val(data);   // 设置刚才插入的记录ID
                    _this.dataId = data;
                    _this.pageStatus = 2;      // 转化为编辑状态
                    
                    $("#panelSlave").show();
                    _InstancePageLines.AutoAdjustTableHeightForLines();
                    
                    $("#ButPrint").show();
                    $("#IsChecked").removeClass().addClass("n2");
                    $("#IsChecked").html("状态：未审核。");
                    $("#IsChecked").show();
                }
            }
        });
    }
    New() {
        super.New();
        $("#HeaderId").val(0);
        $("#ButSave").show();
        $("#panelSlave").hide();
        
        this.FetchNewBillNo();
        this.FetchLocalCurrency();

        // 默认设置一些值
        $("#SignedBy").val($("#UserId").val());
        $("#SignedByName").val($("#UserName").val());
        $("#DateOfSigned").val(getCurrentDate());
        $("#UpdatedByName").val($("#UserName").val());
        $("#UpdatedDate").val(getCurrentDate());

        $("#ContractNo").focus();
    }
    FetchNewBillNo() {
        super.DoAjax(null, "/manufacture/cpc/header/fetchNewBillNo.html", function (data, $self) {
            $("#ContractNo").val(data.BillNo);
        });
    }
    FetchLocalCurrency() {
        super.DoAjax(null, "/master/currency/fetchLocalCurrency.html", function (data, $self) {
            $("#CurrencyId").val(data.currencyId);
            $("#CurrencyName").val(data.currencyName);
        });
    }
    DoChoiceSecondParty() {
        let _choice = new CommonChoice();
        let params = {};
        params['Flag'] = 0;
        params['CurrentUserId'] = null;
        params['NotInGroupId'] = null;
        _choice.DoChoiceSupplier(params, '选择承揽方', (data) => {
            if (data) {
                // 判断是否数据发生了改变如果改变则设置改变标记
                if ($("#SecondPartyName").val() !== data[1]) {
                    $("#form_data").data("changed", true);
                }
                $("#SecondPartyId").val(data[0]);
                $("#SecondPartyName").val(data[1]);
            }
        });
        $("#SecondPartyName").focus();
    }
    DoChoiceSignedBy() {
        let _choice = new CommonChoice();
        _choice.DoChoiceUser(0, '选择业务代表', '设计', (data) => {
            if (data) {
                // 判断是否数据发生了改变如果改变则设置改变标记
                if ($("#SignedByName").val() !== data[1]) {
                    $("#form_data").data("changed", true);
                }
                $("#SignedBy").val(data[0]);
                $("#SignedByName").val(data[1]);
            }
        });
        $("#SignedByName").focus();
    }
    DoChoiceTaxRate() {
        let _choice = new CommonChoice();
        _choice.DoChoiceTaxRate(0, (data) => {
            if (data) {
                // 判断是否数据发生了改变如果改变则设置改变标记
                if ($("#TaxRate").val() !== data[1]) {
                    $("#form_data").data("changed", true);
                }
                $("#TaxRateId").val(data[0]);
                $("#TaxRate").val(data[1]);
            }
        });
        $("#TaxRate").focus();
    }
    DoChoiceCurrency() {
        let _choice = new CommonChoice();
        _choice.DoChoiceCurrency(0, (data) => {
            if (data) {
                // 判断是否数据发生了改变如果改变则设置改变标记
                if ($("#CurrencyName").val() !== data[1]) {
                    $("#form_data").data("changed", true);
                }
                $("#CurrencyId").val(data[0]);
                $("#CurrencyName").val(data[1]);
            }
        });
        $("#CurrencyName").focus();
    }
    ShowPageElement() {
        $("Button.act__save").show();
        if (!$("span.act__delete").hasClass("act__delete")) {
            $("span.act__delete").addClass("trash");
            $("span.act__delete i").addClass("fa-all fa-trash-o fa-1");
        }
    }
    HidePageElement() {
        $("Button.act__save").hide();
        $("span.act__delete").removeClass("trash");
        $("span.act__delete i").removeClass("fa-all fa-trash-o fa-1");
    }
    Expand() {
        super.Expand(function () {
            // 自适应高度
            _InstancePageLines.AutoAdjustTableHeightForLines();
            _InstancePageLinesMo.AutoAdjustTableHeightForLines();
        });
    }
    /* 折叠 */
    Collapse() {
        super.Collapse(function () {
            // 自适应高度
            _InstancePageLines.AutoAdjustTableHeightForLines();
            _InstancePageLinesMo.AutoAdjustTableHeightForLines();
        });
    }
}

//------------------------------------------------------------------------------
// 本次生产情况
//------------------------------------------------------------------------------
class MyPageLinesMo extends BaseEditSlave {
    constructor() {
        super('', '', '');
    }
    BuildDataTable(result) {
        $("#tabData21 tbody").empty();
        // 得到数据列表
        if (result === null || result.length === 0) {    // 批量删除(全部删)后返回的数组长度为0
            $("#panelSlave").show();
            this.rows = 0;
            this.AutoAdjustTableHeightForLines();
            return false;
        }
        let content = '';
        this.rows = result.length;        // 设置表格记录数
        this.numCheckbox = result.length;  // 设置表格记录数
        for (let i = 0; i < result.length; i++) {
            content += '<tr _mash_id="' + result[i].linesId + '">';
            content += '<td style="padding-left:6px;"><label class="btn" for="R-' + result[i].linesId + '"><input id="R-' + result[i].linesId + '" name="_check_row" type="checkbox" onclick="_InstancePageLinesMo.DoCheckRow($(this),\'_check_row\', $(\'#CheckAll\'));" value="' + result[i].linesId + '"/><i></i><span></span></label></td>';
            //if ($("#ActionAcl_4").length === 0 || parseInt($("#ActionAcl_4").val() === 0)) {
            //    content += '<td></td>';
            //} else {
            content += '<td class="column__action"><span title="删除" class="trash act__delete" onclick="_InstancePageLinesMo.DeleteLines(\'' + result[i].linesId + '\',$(this));"><i class="fa-all fa-trash-o fa-1"></i></span></td>';
            //}
            if (i > 0) {
                if (result[i].soNo === result[i - 1].soNo && result[i].styleNo === result[i - 1].styleNo &&
                        result[i].colourName === result[i - 1].colourName) {
                    content += '<td style="border-bottom:none;"></td>';
                    content += '<td style="border-bottom:none;"></td>';
                    content += '<td style="border-bottom:none;"></td>';
                    content += '<td style="text-align:center;">' + formatNullData(result[i].uomName) + '</td>';
                    content += '<td style="border-bottom:none;"></td>';
                } else {
                    content += '<td style="border-top:1px solid #c6c3bd; border-bottom:none;">' + formatNullData(result[i].soNo) + '</td>';
                    content += '<td style="border-top:1px solid #c6c3bd; border-bottom:none;">' + formatNullData(result[i].styleNo) + '</td>';
                    content += '<td style="border-top:1px solid #c6c3bd; border-bottom:none;">' + formatNullData(result[i].productName) + '</td>';
                    content += '<td style="text-align:center;">' + formatNullData(result[i].uomName) + '</td>';
                    content += '<td style="border-top:1px solid #c6c3bd; border-bottom:none;">' + formatNullData(result[i].colourName) + '</td>';
                }
            } else {
                content += '<td style="border-bottom:none;">' + formatNullData(result[i].soNo) + '</td>';
                content += '<td style="border-bottom:none;">' + formatNullData(result[i].styleNo) + '</td>';
                content += '<td style="border-bottom:none;">' + formatNullData(result[i].productName) + '</td>';
                content += '<td style="text-align:center;">' + formatNullData(result[i].uomName) + '</td>';
                content += '<td style="border-bottom:none;">' + formatNullData(result[i].colourName) + '</td>';
            }
            content += '<td style="text-align:center;">' + formatNullData(result[i].sizeName) + '</td>';
            content += '<td>' + formatNullData(result[i].moQuantity) + '</td>';
            content += '<td>' + formatNullData(result[i].finishedQuantity) + '</td>';
            content += '<td class="edited-cell">' + formatNullData(result[i].contractQuantity) + '</td>';
            content += '</tr>';

            $('#tabData21 tbody').append(content);
            content = '';
        }
        // 设置明细部分高度
        this.AutoAdjustTableHeightForLines();
        setOneTableRowColor("tabData21");
        $("#panelSlave").show();

        let _cell_id = "_cell__field";
        let _cell_name = "__cell__field";
        $('#tabData21 tbody tr').find("td.edited-cell").click(function () {
            OnCellClickEvent($(this), _cell_id, _cell_name, 0);
        });
    }
    // 增加本次合同生产情况记录
    NewLines() {
        let _choice = new CommonChoice();
        _choice.DoChoiceProduct(1, '选择款号', (data) => {
            if (data) {
                let _result = [];
                for (let i = 0; i < data.length; i++) {
                    let item = {};
                    item['headerId'] = parseInt($("#HeaderId").val());
                    item['contractNo'] = $("#ContractNo").val();
                    item['productId'] = parseInt(data[i]['productId']);
                    item['createdBy'] = parseInt($.trim($("#UserId").val()));
                    item['updatedBy'] = parseInt($.trim($("#UserId").val()));
                    _result.push(item);
                }
                this.ImportMoLinesIntoLines(_result);
            }
        });
    }
    // 新增加工明细记录,后台同时更新了合同明细表
    ImportMoLinesIntoLines(_result) {
        super.DoAjax(_result, '/manufacture/cpc/mo_lines/insert.html', function (data, $self) {
            // 刷新合同明细
            if (data.LinesList.length > 0) {
                _InstancePageLines.BuildDataTable(data.LinesList);
            }
            // 刷新加工明细
            if (data.LinesMoList.length > 0) {
                $self.BuildDataTable(data.LinesMoList);
            }
            // 更新总金额
            $("#Amount").val(data.Amount);

            ShowSuccessMessagePanel("增加成功。");
        });
    }
    // 获取本次合同生产情况数据
    GetLinesData() {
        let _result = [];
        $('#tabData21 tbody').find("tr").each(function () {
            if ($(this).find('td.dirty').length > 0) {
                let item = {};
                item['headerId'] = $("#HeaderId").val();
                item['contractNo'] = $("#ContractNo").val();
                item['linesId'] = $(this).attr('_mash_id');
                item['contractQuantity'] = formatNullInputValue($.trim($(this).find('td').eq(10).text())) === null ? 0 : $(this).find('td').eq(10).text();
                item['updatedBy'] = $.trim($("#UserId").val());
                _result.push(item);
            }
        });
        return JSON.stringify(_result);
    }
    // 更新本次合同生产情况
    SaveLines() {
        //step 1、进行页面验证，失败则返回
        let success_01 = CheckGridInput02();
        if (!success_01)
            return;

        super.SaveLines("/manufacture/cpc/mo_lines/update.html", function (data, $self) {
            // 刷新本次合同生产情况
            $self.BuildDataTable(data.LinesMoList);
            // 刷新合同明细
            _InstancePageLines.BuildDataTable(data.LinesList);
            // 更新总金额
            $("#Amount").val(data.Amount);

            ShowSuccessMessagePanel("保存成功。");
        });
    }
    // 删除本次合同生产情况
    DeleteLines(linesId, $self) {
        let params = {};
        params['headerId'] = $("#HeaderId").val();
        params['linesId'] = linesId;
        params['contractNo'] = $("#ContractNo").val();
        params['styleNo'] = $self.parent().parent().parent().find("td").eq(3).text();
        params['colourName'] = $self.parent().parent().parent().find("td").eq(6).text();
        params['sizeName'] = $self.parent().parent().parent().find("td").eq(7).text();
        params['deletedBy'] = $.trim($("#UserId").val());
        super.DeleteLines(params, "/manufacture/cpc/mo_lines/delete.html", function (data, $self) {
            // 刷新本次合同生产情况
            $self.BuildDataTable(data.LinesMoList);
            // 刷新合同明细
            _InstancePageLines.BuildDataTable(data.LinesList);
            // 更新总金额
            $("#Amount").val(data.Amount);

            ShowSuccessMessagePanel("删除成功。");
        });
    }
    // 批量选择的数据(类中data:this.GetCheckedLinesData)
    GetCheckedLinesData() {
        let choiced_data = [];
        if ($("input[type='checkbox'][name='_check_row']:checked").length > 0) {
            $("input[type='checkbox'][name='_check_row']:checked").each(function () {
                let item = {};
                item['headerId'] = $("#HeaderId").val();
                item['contractNo'] = $.trim($("#ContractNo").val());
                item['linesId'] = $(this).parent().parent().parent().attr("_mash_id");
                item['deletedBy'] = $.trim($("#UserId").val());
                choiced_data.push(item);
            });
        }
        return JSON.stringify(choiced_data);
    }
    BatchDeleteLines() {
        if ($("input[type='checkbox'][name='_check_row']:checked").length <= 0) {
            ShowErrorMessagePanel("请选择要删除的数据。");
            return false;
        }
        super.BatchDeleteLines('/manufacture/cpc/mo_lines/batchdelete.html', function (data, $self) {
            // 刷新明细
            $self.BuildDataTable(data.LinesMoList);
            // 刷新合同明细
            _InstancePageLines.BuildDataTable(data.LinesList);
            // 更新总金额
            $("#Amount").val(data.Amount);
            $("#CheckAll").prop("checked", false);
            ShowSuccessMessagePanel("批量删除完成。");
        });
    }
    // 设置行选择后的状态
    SetRowStatus($self) {
        super.AdjustRowStatus($self, function ($row, index) {
            $('#tabData21 tbody tr:eq(' + index + ')').addClass("row__selected");
            // 设置删除按钮失效
            $row.children('td').eq(1).children('span').eq(0).attr("onclick", "");
        }, function ($row, index) {
            $('#tabData21 tbody tr:eq(' + index + ')').removeClass("row__selected");
            // 设置删除按钮有效
            let _event_delete_onclick = '_InstancePageLinesMo.DeleteLines($(this))';
            $row.children('td').eq(1).children('span').eq(0).attr("onclick", _event_delete_onclick);
        });
    }
    AutoAdjustTableHeightForLines() {
        let h = $(window).height();
        let _tabTop = 0;   // 用于随着窗口变化，下面明细高度随之变化的一个节点
        if ($("#panel_slave_butbar_02").css('display') === 'none') {
            _tabTop = $("#panelSlave").offset().top + 71;
        } else {
            _tabTop = $("#panelSlave").offset().top + 96;
        }
        //$("#test").remove();
        //$(document.body).append('<div id="test" style="background:red;width:100%;position:absolute; top:' + _tabTop + 'px;display:block;height:5px;z-index:10000" />');
        let _rc = Math.floor((h - _tabTop - 25) / 25);
        let _dh = _rc * 25;
        let _rowH = this.rows * 25; // 计算行高
        _dh = (_rowH >= _dh) ? _dh : _rowH;

        $("#divD21").css({"max-height": _dh, height: _dh});
    }
}

//------------------------------------------------------------------------------
// 明细处理部分
//------------------------------------------------------------------------------
class MyPageLines extends BaseEditSlave {
    constructor() {
        super('', '', '');
    }
    BuildDataTable(result) {
        $('#tabData11 tbody').empty();
        // 得到数据列表
        if (result === null || result.length === 0) {
            $("#panelSlave").show();
            this.rows = 0;
            // 自适应高度
            this.AutoAdjustTableHeightForLines();
            return false;
        }
        let content = '';
        this.rows = result.length;
        this.numCheckbox = result.length;
        for (let i = 0; i < result.length; i++) {
            content += '<tr _mash_id="' + result[i].linesId + '">';
            content += '<td>' + formatNullData(result[i].productName) + '</td>';
            content += '<td>' + formatNullData(result[i].styleNo) + '</td>';
            content += '<td style="text-align:center;">' + formatNullData(result[i].uomName) + '</td>';
            content += '<td>' + formatNullData(result[i].contractQuantity) + '</td>';
            content += '<td class="edited-cell">' + formatNullData(result[i].processingFee) + '</td>';
            content += '<td>' + formatNullData(window.parseFloat(result[i].amount).toFixed(2)) + '</td>';
            content += '<td class="edited-cell">' + formatNullData(result[i].manufactureDate) + '</td>';
            content += '<td class="edited-cell">' + formatNullData(result[i].materialReceiptedDate) + '</td>';
            content += '<td>' + formatNullData(result[i].materialFinishedDate) + '</td>';
            content += '</tr>';

            $('#tabData11 tbody').append(content);
            content = '';
        }
        setOneTableRowColor("tabData11");
        // 设置明细部分高度
        this.AutoAdjustTableHeightForLines();

        let _cellid = "_cell__field";
        let _cellname = "__cell__field";
        $('#tabData11 tbody tr').find("td.edited-cell").click(function () {
            switch ($(this).index()) {
                case 4:
                    OnCellClickEvent($(this), _cellid, _cellname, 0);
                    break;
                default:
                    OnCellDateEditEvent($(this), _cellid, _cellname);
                    break;
            }
        });

        $("#panelSlave").show();
    }
    GetLinesData() {
        let _result = [];
        $('#tabData11 tbody').find("tr").each(function () {
            if ($(this).find('td.dirty').length > 0) {
                let item = {};
                item['headerId'] = $("#HeaderId").val();
                item['contractNo'] = $("#ContractNo").val();
                item['linesId'] = $(this).attr('_mash_id');
                item['processingFee'] = formatNullInputValue($.trim($(this).find('td').eq(4).text())) === null ? 0 : $(this).find('td').eq(4).text();
                item['manufactureDate'] = formatNullInputValue($.trim($(this).find('td').eq(6).text()));
                item['materialReceiptedDate'] = formatNullInputValue($.trim($(this).find('td').eq(7).text()));
                item['updatedBy'] = $.trim($("#UserId").val());
                _result.push(item);
            }
        });

        return JSON.stringify(_result);
    }
    SaveLines() {
        //step 1、进行页面验证，失败则返回
        let _success = CheckGridInput01();
        if (!_success)
            return;

        super.SaveLines("/manufacture/cpc/lines/update.html", function (data, $self) {
            if (data.LinesList !== undefined) {
                // 刷新合同明细
                $self.BuildDataTable(data.LinesList);
                // 更新主表总金额
                $("#Amount").val(data.Amount);
            }

            ShowSuccessMessagePanel("保存成功。");
        });
    }
    AutoAdjustTableHeightForLines() {
        let h = $(window).height();
        let _tabTop = 0;   // 用于随着窗口变化，下面明细高度随之变化的一个节点
        if ($("#panel_slave_butbar_01").css('display') === 'none') {
            _tabTop = $("#panelSlave").offset().top + 71;
        } else {
            _tabTop = $("#panelSlave").offset().top + 96;
        }
        let _rc = Math.floor((h - _tabTop - 25) / 25);
        let _dh = _rc * 25;
        let _rowH = this.rows * 25; // 计算行高
        _dh = (_rowH >= _dh) ? _dh : _rowH;
        $("#divD11").css({"max-height": _dh, height: _dh});
    }
}

var _InstancePageHeader = null;
var _InstancePageLinesMo = null;
var _InstancePageLines = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    let _pageStatus = parseInt($("#Action").val());
    let _dataId = $("#HeaderId").val();

    let commission_processing_contract_list_result = $.cookie("commission_processing_contract_list_result") === undefined ? "" : $.cookie("commission_processing_contract_list_result");
    let _pageListData = [];
    if (commission_processing_contract_list_result !== "") {
        _pageListData = commission_processing_contract_list_result.split(',');
        $("#rec_total_rows").text(_pageListData.length);
        $("#rec_cur_row").text($.inArray(_dataId, _pageListData) + 1);

        if (_pageListData.length > 0) {
            let index = $.inArray(_dataId, _pageListData);
            if (index === 0) {
                $("#ButPrev").attr("disabled", "disabled");
            } else {
                $("#ButNext").removeAttr("disabled");
            }
            if (index === (_pageListData.length - 1)) {
                $("#ButNext").attr("disabled", "disabled");
            } else {
                $("#ButPrev").removeAttr("disabled");
            }
        }
    } else {
        $("#rec_total_rows").text("1");
        $("#rec_cur_row").text("1");
    }

    _InstancePageHeader = new MyPageHeader(_dataId, 0, 0, _pageStatus, _pageListData,
            "/manufacture/cpc/list.html",
            "/manufacture/cpc/header/fetchByKey.html",
            "/manufacture/cpc/header/save.html",
            "/manufacture/cpc/header/export.html",
            "/manufacture/cpc/header/print.html");

    _InstancePageLinesMo = new MyPageLinesMo();
    _InstancePageLines = new MyPageLines();

    $("#tabPanelHeader").wxTabs({tabContent: "tabPanelData"});

    window.laydate.render({
        elem: '#DateOfSigned',
        theme: '#393D49',
        trigger: 'click'
    });

    $("#hPanelSplitter").click(function () {
        if ($(this).children("i").hasClass("fa-angle-double-up")) {
            _InstancePageHeader.Collapse();
        } else {
            _InstancePageHeader.Expand();
        }
    });

    _InstancePageHeader.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
    if (_InstancePageLines !== null)
        _InstancePageLines.AutoAdjustTableHeightForLines();
    if (_InstancePageLinesMo !== null)
        _InstancePageLinesMo.AutoAdjustTableHeightForLines();
}

//-----------------------------------------------------------------------------
// 验证函数
//-----------------------------------------------------------------------------
$.validator.setDefaults({
    ignore: 'hidden, [reaonly=readonly]'
});
$(function () {
    $("#form_data").validate({
        // Step 1：设置验证规则和错误消息
        rules: {
            _ContractNo: "required",
            _DateOfSigned: {
                dateISO: true,
                required: true
            },
            _SecondPartyName: "required",
            _SignedByName: "required",
            _TaxStatus: "required",
            _CurrencyName: "required"
        },
        messages: {
            _ContractNo: "请填写合同号。",
            _DateOfSigned: {
                dateISO: "请填写正确的日期。",
                required: "请填写合同日期。"
            },
            _SecondPartyName: "请填写承揽方。",
            _SignedByName: "请填写业务员。",
            _TaxStatus: "请填写含税状况。",
            _CurrencyName: "请填写币种。"
        },
        // Step 2：设置验证触发事件
        onclick: false,
        onfocusout: false,
        onfocusin: false,
        onkeyup: false,
        onkeydown: false,
        focusInvalid: false,
        // Step 3：设置错误信息提示
        showErrors: window.showErrors  //使用自定义的错误显示方法
    });
});
// 验证输入
function CheckGridInput01() {
    $('#tabData11 tbody').find("tr").each(function () {
        let _fee = $.trim($(this).find('td').eq(4).text()).length > 0 ? $.trim($(this).find('td').eq(4).text()) : 0; //加工费

        if (_fee !== 0) {
            if (!isNumber(_fee)) {
                GridCheckErrHandle($(this), 4, '请输入正确的数字。');
            } else {
                GridCheckSuccessHandle($(this), 4);
            }
        }
    });
    if ($('#tabData11 tbody').find('td.error').length > 0) {
        ShowErrorMessagePanel('对不起，填写的数据有错误。');
        return false;
    } else {
        return true;
    }
}
// 验证输入
function CheckGridInput02() {
    $('#tabData21 tbody').find("tr").each(function () {
        let _quantity = $.trim($(this).find('td').eq(10).text()).length > 0 ? $.trim($(this).find('td').eq(10).text()) : 0; // 数量

        if (_quantity !== 0) {
            if (!isNumber(_quantity)) {
                GridCheckErrHandle($(this), 10, '请输入正确的数字。');
            } else {
                GridCheckSuccessHandle($(this), 10);
            }
        }
    });

    if ($('#tabData21 tbody').find('td.error').length > 0) {
        ShowErrorMessagePanel('对不起，填写的数据有错误。');
        return false;
    } else {
        return true;
    }
}
function GridCheckErrHandle($row, index, errMsg) {
    $row.find('td').eq(index).addClass("error");
    $row.find('td').eq(index).attr('title', errMsg);
}
function GridCheckSuccessHandle($row, index) {
    $row.find('td').eq(index).removeClass("error");
    $row.find('td').eq(index).attr('title', '');
}